package com.ln.cmsln.controller.yang;


import com.alibaba.fastjson.JSON;
import com.ln.cmsln.pojo.entity.yang.Jiaoyan;
import com.ln.cmsln.pojo.entity.yang.TouOne;
import com.ln.cmsln.service.yang.TouOneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Helen
 * @since 2022-03-31
 */
@Api(tags = "大头区1")
@RestController
@CrossOrigin
@RequestMapping("/api/touOne")
public class TouOneController {

    @Resource
    private TouOneService touOneService;

    @GetMapping("/findAll")
    public List<TouOne> findAll(){
        List<TouOne> selectUser = touOneService.findAll();
        return selectUser;
    }

    @PostMapping("/findLayui")
    public Object findLayui(){
        List<TouOne> list  = touOneService.findAll();
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("count", 0);
        map.put("data", list);
        String json= JSON.toJSONString(map);
        return json;
    }

    @ApiOperation("删除信息")
    @PostMapping("/remove")
    public int remove(Long tId){
        try {
            touOneService.remove(tId);
            return 1;
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }


    @ApiOperation("添加信息")
    @PostMapping("add")
    public int add(TouOne touOne) {
        int res = touOneService.add(touOne);
        return res ;
    }


    @ApiOperation("修改信息")
    @PostMapping("/update")
    public boolean update(@ApiParam(value = "新增图片信息", required = true)TouOne touOne,
                          @ApiParam(value = "新增图片文件", required = false) MultipartFile file
    ){
        final String property = System.getProperty("user.dir");
        return touOneService.update(touOne,property,file);
    }

}

